import { IFeidaoAiNodejsComponent } from '@feidao/web/interfaces';

import server_render from '../atom-n/server-render';
import { Params } from '../atom-n/params2query';
import p2q from '../atom-n/params2query';

import nodejs from '@feidao/web/atom/nodejs/msg/nodejs';
import render from '@feidao/web/atom/nodejs/render/render';

import P02 from './P02';
import P04 from './P04';
import P13 from './P13';

export default async function (fd: IFeidaoAiNodejsComponent, ...args: any[]) {
	console.log('zj-h5manage-001==========', args);
	let page_no = fd.data.params['page_no'];
	if (!page_no) {
		page_no = 1;
	}
	let page_size = fd.data.params['page_size'];
	if (!page_size) {
		page_size = 20;
	}
	const q = p2q(fd.data.params as Params);
	const query = {
		data: {
			criteria: q.criteria,
			sort: q.sort,
			page_no,
			page_size
		}
	};
	const res = await nodejs("xmedia", "moxuan_find_h5_playback_content", query);
	// 无数据渲染P04
	if (res.dataArray.length == 0) {
		server_render(fd.data.node, 'P04', P04, '');
	} else {
		server_render(fd.data.node, 'P02', P02, res.dataArray);
	}
	res['page_size'] = page_size;
	render(fd.data.node, res, P13, 'inner');
}
